package cn.yunhe.service.serviceImpl;

import cn.yunhe.dao.QuestionDao;
import cn.yunhe.entity.Question;
import cn.yunhe.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
@Service("questionService")
public class QuestionServiceImpl implements QuestionService {

   @Autowired
   @Qualifier("questionDao")
    private QuestionDao questionDao;
    @Override
    public List<Question> getQuestionList() {
        return questionDao.getQuestionList();
    }

    @Override
    public Question getQuestionById(int id) {
        return questionDao.getQuestionById(id);
    }

    /**
     * 获取对的题的数量
     * @param strList
     * @return
     */
    public int getTrueCount(String strList){
        List list = Arrays.asList(strList.split(","));
        int count = 0;
        if(strList.length() > 0){
            for (int i = 0; i < list.size(); i++) {
                List tmp = Arrays.asList(list.get(i).toString().split(":"));
                int id = Integer.parseInt((String) tmp.get(0));
                Question question = getQuestionById(id);
                if (question.getAnswer().equalsIgnoreCase((String) tmp.get(1))) {
                    count++;
                }
            }
        }
        return count;
    }


}
